//
//  ModeLayer.h
//  FamousWarrior
//
//  Created by shuaixitao on 13-4-26.
//  Copyright (c) 2013年 Moqikaka. All rights reserved.
//

// NOTO::用于同一场景中添加到顶层的Layer需要屏蔽底层触摸事件

#ifndef __MODELAYER__
#define __MODELAYER__


#include "cocos2d.h"

USING_NS_CC;

// 内存分配时保持内存对齐的方式
char* allocateAligned(size_t bytes) {
    const int align = sizeof(void*);    // We'll align to pointer size
    assert((align & (align-1)) == 0);   // Pointer size should be a power of 2
    size_t current_mod = reinterpret_cast<uintptr_t>(alloc_ptr_) & (align-1);
    size_t slop = (current_mod == 0 ? 0 : align - current_mod);
    size_t needed = bytes + slop;
    char* result;
    if (needed <= alloc_bytes_remaining_) {
        result = alloc_ptr_ + slop;
        alloc_ptr_ += needed;
        alloc_bytes_remaining_ -= needed;
    } else {
        // AllocateFallback always returned aligned memory
        result = AllocateFallback(bytes);
    }
    assert((reinterpret_cast<uintptr_t>(result) & (align-1)) == 0);
    return result;
}



class ModalLayer : public CCLayer
{
public:
    ModalLayer();
    ~ModalLayer();
    static CCScene* scene();
    CREATE_FUNC(ModalLayer);
    
public:
    virtual bool init();
    virtual void registerWithTouchDispatcher();
    
    virtual bool ccTouchBegan (cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent) {return true;}
    virtual void ccTouchMoved (cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent){};
    virtual void ccTouchEnded (cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent){};
};

class ModalLayerColor : public CCLayerColor
{
public:
    static CCScene* scene(const ccColor4B& color);
    static ModalLayerColor* create(const ccColor4B& color);
    ModalLayerColor();
    ~ModalLayerColor();
   
public:
    virtual bool init(const ccColor4B& color);
    virtual void registerWithTouchDispatcher();
    
    virtual bool ccTouchBegan (cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent) {return true;}
    virtual void ccTouchMoved (cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent){};
    virtual void ccTouchEnded (cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent){};

};

#endif /* defined(__MODELAYER__) */
